# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: rubicon <rubicon@mailo.com>
pkgname=hime
pkgver=0.9.12_git20220426
_gitrev=c66f0671a4d2a9e35d68c4e11af8986ffadc2d4f
pkgrel=0
pkgdesc="HIME Input Method Editor"
url="https://hime-ime.github.io/"
arch="all"
license="LGPL-2.1-or-later AND GPL-2.0-or-later"
depends="bash cmd:whereis"
makedepends="
	bash
	libxtst-dev
	cmd:whereis
	cmd:iconv
	anthy-dev
	libchewing-dev
	gtk+2.0-dev
	gtk+3.0-dev
	qt5-qtbase-dev
	qt6-qtbase-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-lang
	$pkgname-dev
	$pkgname-anthy
	$pkgname-chewing
	$pkgname-gtk2
	$pkgname-gtk3
	$pkgname-qt5
	$pkgname-qt6
	"
options="!check"
source="$pkgname-$pkgver.tar.gz::https://github.com/hime-ime/hime/archive/$_gitrev/hime-$_gitrev.tar.gz
	use-bash-not-sh.patch
	fix-im-client-ldflags.patch
	"
builddir="$srcdir/hime-$_gitrev"

build() {
	./configure --prefix=/usr \
		--with-gtk=2.0 \
		--qt6-moc-path=/usr/lib/qt6/libexec/moc
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

anthy() {
	pkgdesc="$pkgdesc (Anthy Hiragana support)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel anthy"
	amove usr/lib/hime/anthy-module.so
}

chewing() {
	pkgdesc="$pkgdesc (Chewing Bopomofo support)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel libchewing"
	amove usr/lib/hime/chewing-module.so
}

gtk2() {
	pkgdesc="$pkgdesc (Gtk+2 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel gtk+2.0"
	install="$subpkgname.post-install $subpkgname.post-upgrade"
	amove usr/lib/gtk-2.0/*/immodules/im-hime.so
}

gtk3() {
	pkgdesc="$pkgdesc (Gtk+3 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel gtk+3.0"
	install="$subpkgname.post-install $subpkgname.post-upgrade"
	amove usr/lib/gtk-3.0/*/immodules/im-hime.so
}

qt5() {
	pkgdesc="$pkgdesc (Qt5 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel qt5-qtbase-x11"
	amove usr/lib/qt5/plugins/platforminputcontexts/im-hime.so
}

qt6() {
	pkgdesc="$pkgdesc (Qt6 immodule)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel qt6-qtbase-x11"
	amove usr/lib/qt6/plugins/platforminputcontexts/im-hime.so
}

sha512sums="
808766419ee1ea17b2dc162667e2213ac5b1a2882d64218d2636f3ca72db9de24bc7a262b88bc52fe84ffee5b60b1964406f9fd5324b44503de31f1c4b60cc06  hime-0.9.12_git20220426.tar.gz
4e38121579f986fd90b926e77e413b81ee0001a6cba1ae1be14e66b22b2b9ac172dfd9ed1d51c15040bfab5135c2bd8214edb97e762648059aaa92162cab3a2c  use-bash-not-sh.patch
80fd7ff717bdac553e440dedc84d0db9785f0e775a7848dda9e92f1da9018713714ced7a9f6fe9120a2b0d9e3d49a4eb25557432d21f01a5e4298506a3aa21d9  fix-im-client-ldflags.patch
"
